package com.ossjk.oa.finance.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ossjk.oa.finance.entity.Reimburse;
import com.ossjk.oa.finance.vo.ReimVo;

/**
 * <p>
 * 报销 Mapper 接口
 * </p>
 *
 * @author chair
 * @since 2019-02-07
 */
public interface ReimburseMapper extends BaseMapper<Reimburse> {
	
	@Select("select * from v_reims 	${ew.sqlSegment}")
	List<ReimVo> selectVosPage(Page page, @Param("ew") Wrapper wrapper );
	
	@Select("select * from v_reims 	${ew.sqlSegment}")
    List<ReimVo> selectVos( @Param("ew") Wrapper wrapper );
	
	@Select("select * from v_reims2 ${ew.sqlSegment}")
    List<ReimVo> selectVos2( @Param("ew") Wrapper wrapper );
	
	@Select("select * from v_reims5 ${ew.sqlSegment}")
    List<ReimVo> selectVos5( @Param("ew") Wrapper wrapper );
	
	@Select("select left(edtm,7) as edtm,dname,eid,rname,max(rwst) as rwst,count(id) as cntsub,sum(amount) as amount from v_reims ${ew.sqlSegment}")
	List<ReimVo> selectMthVos( @Param("ew") Wrapper wrapper );
	
	@Select("select  a.crer AS eid,d.rname AS rname, a.rwst AS rwst,d.dname AS dname, min(a.sttm) AS sttm,max(a.edtm) AS edtm,  sum(a.amount) AS amount,count(a.amount) AS cntsub " + 
			" from  reimburse a , v_emp2dept d where a.isdelete=1 and a.crer=d.id ${ew.sqlSegment}")
	List<ReimVo> selectMthVoCount( @Param("ew") Wrapper wrapper );
	
    @Select("select   left(max(edtm),7) from reimburse where edtm<(select min(edtm) from reimburse where left(edtm,7) = #{mth}) order by edtm desc")
    String selectPreMth(String mth);
    
    @Select("select   left(min(edtm),7) from reimburse where edtm>(select max(edtm) from reimburse where left(edtm,7) = #{mth}) order by edtm")
    String selectNextMth(String mth);
    
    //选定月份12个月以内的月份                                                                                                                                                                                                                                                                      //往前减12月
    @Select("select a.rmMth  from (select DISTINCT left(edtm,7) as rmMth  from   reimburse ) a where  a.rmMth >#{mth} order by a.rmMth desc limit 0,12")
    String[] selectMax12Mth(String mth);

}
